using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using WIT.DAQ.Core.Models;

namespace WIT.DAQ.Core.Forms;

/// <summary>
/// 基类窗口
/// </summary>
internal class BaseForm : Form
{
	/// <summary>
	/// Required designer variable.
	/// </summary>
	private IContainer components = null;

	/// <summary>
	/// 构造函数
	/// </summary>
	internal BaseForm()
	{
		InitializeComponent();
	}

	/// <summary>
	/// 窗体按键事件
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	private void BaseForm_KeyDown(object sender, KeyEventArgs e)
	{
		if (e.Modifiers != Keys.Alt || e.KeyCode != Keys.R)
		{
			return;
		}
		if (Common.COMMAND_FORM == null)
		{
			Common.COMMAND_FORM = new CommandForm
			{
				Icon = base.Icon,
				StartPosition = FormStartPosition.Manual
			};
			Common.COMMAND_FORM.Disposed += delegate
			{
				Common.COMMAND_FORM = null;
			};
			Rectangle workingArea = Screen.GetWorkingArea(this);
			Common.COMMAND_FORM.Location = new Point(0, workingArea.Height - Common.COMMAND_FORM.Height);
			Common.COMMAND_FORM.Show();
			return;
		}
		if (!Common.COMMAND_FORM.Visible)
		{
			Common.COMMAND_FORM.Visible = true;
		}
		if (Common.COMMAND_FORM.WindowState == FormWindowState.Minimized)
		{
			Common.COMMAND_FORM.WindowState = FormWindowState.Normal;
		}
		Rectangle workingArea2 = Screen.GetWorkingArea(this);
		Common.COMMAND_FORM.Location = new Point(0, workingArea2.Height - Common.COMMAND_FORM.Height);
		Common.COMMAND_FORM.Activate();
	}

	/// <summary>
	/// 打开实时监控窗口
	/// </summary>
	/// <param name="station"></param>
	internal void ShowMonitorForm(Station station = null)
	{
		if (Common.MONITOR_FORM != null)
		{
			Common.MONITOR_FORM.Dispose();
		}
		Common.MONITOR_FORM = new MonitorForm(station)
		{
			Icon = base.Icon,
			StartPosition = FormStartPosition.CenterScreen
		};
		Common.MONITOR_FORM.Disposed += delegate
		{
			Common.MONITOR_FORM = null;
		};
		Common.MONITOR_FORM.Show();
	}

	/// <summary>
	/// Clean up any resources being used.
	/// </summary>
	/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
	protected override void Dispose(bool disposing)
	{
		if (disposing && components != null)
		{
			components.Dispose();
		}
		base.Dispose(disposing);
	}

	/// <summary>
	/// Required method for Designer support - do not modify
	/// the contents of this method with the code editor.
	/// </summary>
	private void InitializeComponent()
	{
		base.SuspendLayout();
		base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 12f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.ClientSize = new System.Drawing.Size(800, 450);
		base.KeyPreview = true;
		base.Name = "BaseForm";
		this.Text = "BaseForm";
		base.KeyDown += new System.Windows.Forms.KeyEventHandler(BaseForm_KeyDown);
		base.ResumeLayout(false);
	}
}
